package com.ht.base.system.biz.client.impl;

import com.ht.base.system.biz.manager.SysUserManager;
import com.ht.base.system.client.SysUserClient;
import com.ht.base.system.common.pojo.bo.SysUserBO;
import com.ht.base.system.common.pojo.qto.SysUserQTO;
import org.base.common.appexception.AppException;
import org.base.common.appexception.ResultData;
import org.base.common.page.PageBO;
import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author hdengxian
 * @Date 2023/8/11 8:50
 */
@DubboService
@Component
public class SysUserClientImpl implements SysUserClient {
    Logger logger = LoggerFactory.getLogger(SysUserClientImpl.class);

    @Resource
    private SysUserManager sysUserManager;

    @Override
    public ResultData<SysUserBO> insertUser(SysUserBO userBO) throws AppException {
        logger.info("SysUserClientImpl.insertUser - 新增方法调用成功。");
        ResultData<SysUserBO> data = new ResultData<>();
        data.setData(new SysUserBO());
        return data;
    }

    @Override
    public ResultData<Boolean> updateUser(SysUserBO userBO) throws AppException {
        ResultData<Boolean> resultData = null;
        try {
            resultData = new ResultData<>(sysUserManager.updateUser(userBO));
        } catch (AppException e) {
            throw new AppException(e.getResponseCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("SysUserClientImpl.updateUser - system系统异常 - e - {}", e);
            throw new AppException("system服务系统异常！");
        }
        return resultData;
    }

    @Override
    public ResultData<Boolean> deleteUser(Long sysUserId) throws AppException {
        return new ResultData<>(sysUserManager.deleteUser(sysUserId));
    }

    @Override
    public ResultData<SysUserBO> findByUserId(Long sysUserId) throws AppException {
        return new ResultData<>(sysUserManager.findByUserId(sysUserId));
    }

    @Override
    public ResultData<SysUserBO> findUserByLoginNo(String loginNo) {
        SysUserBO userBO = sysUserManager.findUserByLoginNo(loginNo);
        return new ResultData<>(userBO);
    }

    @Override
    public ResultData<PageBO<SysUserBO>> findUserForPage(SysUserQTO qto) throws AppException {
        PageBO<SysUserBO> pageBO = sysUserManager.findUserForPage(qto);
        return new ResultData<>(pageBO);
    }


}
